/* UTF8 Encoding */
/*-----------------------------------------------------------------------
|                            FILE DESCRIPTION                           |
-----------------------------------------------------------------------*/
/*----------------------------------------------------------------------
  - File name     : cprint.hpp
  - Author        : liuzhihua (liuzhihuawy@163.com)
  - Update date   : 2024.03.09
  - Brief         : data format out
  - Version       : v0.1
-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
|                               UPDATE NOTE                             |
-----------------------------------------------------------------------*/
/**
  * Update note:
  * ------------   ---------------   ----------------------------------
  *     Date            Author                      Note
  * ------------   ---------------   ----------------------------------
  *  2024.02.29       liuzhihua                  Create file          
***/

#ifndef CPRINT_H
#define CPRINT_H

/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/
#include <stdint.h>
#include "cQueue.h"
/*-----------------------------------------------------------------------
|                                DEFINES                                |
-----------------------------------------------------------------------*/
typedef int (*pWrite_func_t)(const uint8_t *data, int dataSize);

class cprint
{
private:
    cQueue_t *queue;     // 队列句柄
    uint8_t *pBuffer;    // 格式化缓存
    uint16_t bufferSize; // 缓存尺寸
    uint16_t writeWait;  // 队列外部发送中的字符数
    const pWrite_func_t write_callback;  // 阻塞输出回调,返回发送字节数
    pWrite_func_t qwrite_callback; // 队列输出回调,返回发送字节数
public:
    cprint( uint8_t* pbuffer,
            uint16_t bufferSize,
            pWrite_func_t writeCallback);

    ~cprint();
    void queue_init(cQueue_t *pcQ, uint8_t *pBuffer, uint16_t size, pWrite_func_t qwriteCallback);

    int format(const char *fmt, ...);
    uint8_t *readBuffer(uint16_t size);

    int print(const char *fmt, ...);
    int print(const char *str);
    int print(const uint8_t *data, int dataSize);
    int print(void);

    int qprint(const char *fmt, ...);
    int qprint(const char *str);
    int qprint(const uint8_t *data, int dataSize);

    int push(const char *fmt, ...);
    int push(const char *str);
    int push(const uint8_t *data, int dataSize);

    int pop(uint8_t *data, int dataSize);
    int getSpare(void);
    int getUsage(void);
    void clear(void);

    int exTxDone_callback(void);
};


/*-----------------------------------------------------------------------
|                                  API                                  |
-----------------------------------------------------------------------*/
#ifdef  __cplusplus
    extern "C" {
#endif

#ifdef __cplusplus
	}
#endif
#endif
